package com.bigtotoro.shuiyincamera;

import android.app.Application;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.os.StrictMode;
import android.support.multidex.MultiDex;
import android.util.Log;

import com.bigtotoro.shuiyincamera.csj.TTAdManagerHolder;
import com.bigtotoro.shuiyincamera.model.MyArt;
import com.bigtotoro.shuiyincamera.util.MyUtils;
import com.bigtotoro.shuiyincamera.util.SharedPreferencesUtil;
import com.bytedance.sdk.openadsdk.TTAdConfig;
import com.bytedance.sdk.openadsdk.TTAdConstant;
import com.bytedance.sdk.openadsdk.TTAdSdk;
import com.meituan.android.walle.WalleChannelReader;
import com.umeng.analytics.MobclickAgent;
import com.umeng.commonsdk.UMConfigure;

import org.litepal.LitePal;

import iknow.android.utils.BaseUtils;
import io.microshow.rxffmpeg.RxFFmpegInvoke;

import static com.bigtotoro.shuiyincamera.Constant.CURRENT_CHANNEL;
import static com.bigtotoro.shuiyincamera.Constant.SP_XIEYI;
//import nl.bravobit.ffmpeg.FFmpeg;

/**
 * Created by xiaobing on 2019/3/29.
 */

public class MyApplication extends Application {
    private static MyApplication mInstance;
    @Override
    public void onCreate() {
        super.onCreate();
        mInstance = this;

        //初始化穿山甲广告组件
//        TTAdManagerHolder.init(this);

        BaseUtils.init(this);
        RxFFmpegInvoke.getInstance().setDebug(true);
//        initFFmpegBinary(this);
        LitePal.initialize(this);//初始化litepal
//        LitePal.deleteAll(MyArt.class);

        StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
        StrictMode.setVmPolicy(builder.build());
        builder.detectFileUriExposure();


        String channel = WalleChannelReader.getChannel(this.getApplicationContext());
        if(channel==null||channel.equals("")){
            channel = "dev";
//            channel = "SHUIYINXIANGJI_QISONG";
        }
        Log.i("SplashActivity", "MyApplication,current_channel===" + channel);
        SharedPreferencesUtil.getInstance(this).putSP(CURRENT_CHANNEL, channel);

        // 初始化SDK
        UMConfigure.init(this, Constant.UMENG_APPKEY, channel, UMConfigure.DEVICE_TYPE_PHONE, null);
        // 选用MANUAL页面采集模式
        MobclickAgent.setPageCollectionMode(MobclickAgent.PageMode.MANUAL);
        MobclickAgent.setScenarioType(this,MobclickAgent.EScenarioType.E_UM_NORMAL);//友盟统计 场景类型设置接口
//        MobclickAgent.setScenarioType(Context context, EScenarioType etype)
        //打开调试模式，正式上线时关闭
        UMConfigure.setLogEnabled(true);

//        MyUtils.getTestDeviceInfo(MyApplication.getInstance().getApplicationContext());//友盟统计集成测试
    }

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        MultiDex.install(this);
    }


    public static synchronized MyApplication getInstance() {
        return mInstance;
    }

    //FFmpeg修改
//    private void initFFmpegBinary(Context context) {
//        if (!FFmpeg.getInstance(context).isSupported()) {
//            Log.e("ZApplication","Android cup arch not supported!");
//        }
//    }
}
